package com.example.arithmeticleetcode.leetcode.august;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-08-04 10:01
 **/
public class Demo02 {

    public static void main(String[] args) {
        System.out.println(subtractProductAndSum(234));//15
        System.out.println(subtractProductAndSum(4421));//21

        System.out.println("第三方资金流水号".getBytes().length);
        System.out.println("第三方资金流水号".toCharArray().length);
    }


    public static int subtractProductAndSum(int n) {
        char[] chars = String.valueOf(n).toCharArray();
        if (chars.length == 1) {
            return 0;
        }
        int addResult = chars[0] - 48;
        int multiplyResult = chars[0] - 48;
        for (int i = 1, len = chars.length; i < len; i++) {
            int temp = chars[i] - 48;
            System.out.println("--" + temp);
            addResult += temp;
            multiplyResult *= temp;
        }
        return multiplyResult -addResult;
    }
}
